package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.HolidayConfigType;
import com.ruoyi.erp.service.IHolidayConfigTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 假期配置类型Controller
 * 
 * @author sauger
 * @date 2022-03-18
 */
@Controller
@RequestMapping("/erp/holiday/type")
public class HolidayConfigTypeController extends BaseController
{
    private String prefix = "erp/holiday/type";

    @Autowired
    private IHolidayConfigTypeService holidayConfigTypeService;

    @RequiresPermissions("erp:holiday:type:view")
    @GetMapping()
    public String holidayType()
    {
        return prefix + "/index";
    }

    /**
     * 查询假期配置类型列表
     */
    @RequiresPermissions("erp:holiday:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HolidayConfigType holidayConfigType)
    {
        startPage();
        List<HolidayConfigType> list = holidayConfigTypeService.selectHolidayConfigTypeList(holidayConfigType);
        return getDataTable(list);
    }

    /**
     * 导出假期配置类型列表
     */
    @RequiresPermissions("erp:holiday:type:export")
    @Log(title = "假期配置类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HolidayConfigType holidayConfigType)
    {
        List<HolidayConfigType> list = holidayConfigTypeService.selectHolidayConfigTypeList(holidayConfigType);
        ExcelUtil<HolidayConfigType> util = new ExcelUtil<HolidayConfigType>(HolidayConfigType.class);
        return util.exportExcel(list, "假期配置类型数据");
    }

    /**
     * 新增假期配置类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存假期配置类型
     */
    @RequiresPermissions("erp:holiday:type:add")
    @Log(title = "假期配置类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HolidayConfigType holidayConfigType)
    {
        holidayConfigType.setCreateBy(getLoginName());
        return toAjax(holidayConfigTypeService.insertHolidayConfigType(holidayConfigType));
    }

    /**
     * 修改假期配置类型
     */
    @RequiresPermissions("erp:holiday:type:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        HolidayConfigType holidayConfigType = holidayConfigTypeService.selectHolidayConfigTypeById(id);
        mmap.put("holidayConfigType", holidayConfigType);
        return prefix + "/edit";
    }

    /**
     * 修改保存假期配置类型
     */
    @RequiresPermissions("erp:holiday:type:edit")
    @Log(title = "假期配置类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HolidayConfigType holidayConfigType)
    {
        return toAjax(holidayConfigTypeService.updateHolidayConfigType(holidayConfigType));
    }

    /**
     * 删除假期配置类型
     */
    @RequiresPermissions("erp:holiday:type:remove")
    @Log(title = "假期配置类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(holidayConfigTypeService.deleteHolidayConfigTypeByIds(ids));
    }
}
